package com.xunk.scene.api.factory;

import com.xunk.common.core.web.domain.AjaxResult;
import com.xunk.scene.api.RemoteSceneService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: HIM
 * @Package: com.xunk.scene.api.factory
 * @ClassName: RemoteSceneFallbackFactory
 * @Author: luanzhiwei
 * @Description: 服务降级
 * @Date: 2021/5/14 10:29
 * @Version: 1.0
 */
@Component
@Slf4j
public class RemoteSceneFallbackFactory implements FallbackFactory<RemoteSceneService> {
    /**
     * Returns an instance of the fallback appropriate for the given cause
     *
     * @param cause corresponds to {@links AbstractCommand#getExecutionException()}
     *              often, but not always an instance of {@links FeignException}.
     */
    @Override
    public RemoteSceneService create(Throwable cause) {
        log.error("服务调用失败，服务降级");
        return new RemoteSceneService() {

            /**
             * 设备信息通知场景服务
             *
             * @param deviceSn
             * @param type
             * @param value
             */
            @Override
            public void sceneNotify(String deviceSn, String type, String value) {
            }

            @Override
            public AjaxResult execCron(String sceneId) {
                return AjaxResult.error();
            }
        };
    }
}
